cmake_minimum_required(VERSION 3.16)

project(appcohub-client VERSION 0.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)

set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(FLUENTUI_BUILD_EXAMPLES OFF)
set(FLUENTUI_BUILD_FRAMELESSHELPERS OFF)

message(STATUS "C++ STANDARD: ${CMAKE_CXX_STANDARD}")
message(STATUS "BUILD TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "SYSTEM TYPE: ${CMAKE_SYSTEM_NAME}")
message(STATUS "Good Luck!")

# 编译模式配置
add_compile_options(-Wall -Wextra -Wpedantic -Wno-unused-variable)
add_compile_options(-Wfatal-errors)
add_compile_options(-Werror=return-type)

if (CMAKE_BUILD_TYPE STREQUAL Release)
    add_compile_options(-O3 -march=native)
elseif (CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
    add_compile_options(-O3 -march=native -g)
#    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=leak -fsanitize=thread -fsanitize=undefined -fsanitize=memory")
    add_definitions(-DDEBUG)
elseif (CMAKE_BUILD_TYPE STREQUAL MiniSizeRel)
    add_compile_options(-Os -march=native)
elseif (CMAKE_BUILD_TYPE STREQUAL Debug)
    add_compile_options(-O0 -g)
    #    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=leak -fsanitize=thread -fsanitize=undefined -fsanitize=memory")
    add_definitions(-DDEBUG)
endif ()

find_package(Qt6 6.2 COMPONENTS Quick REQUIRED)

find_package(openssl)

qt_add_executable(appcohub-client
    src/main.cpp
)

qt_add_resources(appcohub-client
    PREFIX "/"
    FILES window/MainWindow.qml
    FILES component/CodeExpander.qml
    FILES viewmodel/SettingsViewModel.qml
    FILES viewmodel/TextBoxViewModel.qml
    FILES global/ItemsFooter.qml
    FILES global/ItemsOriginal.qml
    FILES global/Lang.qml
    FILES global/qmldir
    FILES res/image/cohub.ico
    FILES window/LoginWindow.qml
    FILES page/SettingsPage.qml
    FILES page/HomePage.qml
    FILES res/image/banner.png
    FILES component/AvatarView.qml
    FILES page/ChatPage.qml
    FILES page/MorePage.qml
    FILES page/CalendarPage.qml
    FILES page/FilePage.qml
    FILES page/MemberPage.qml
    FILES page/ProjectPage.qml
    FILES res/svg/avatar_1.svg res/svg/avatar_10.svg res/svg/avatar_11.svg res/svg/avatar_12.svg res/svg/avatar_2.svg res/svg/avatar_3.svg res/svg/avatar_4.svg res/svg/avatar_5.svg res/svg/avatar_6.svg res/svg/avatar_7.svg res/svg/avatar_8.svg res/svg/avatar_9.svg res/svg/home.svg res/svg/home_dark.svg

)

qt_add_qml_module(appcohub-client
    URI cohub-client
    VERSION 1.0
    QML_FILES main.qml
    RESOURCES resource.qrc
    SOURCES src/main.cpp
    SOURCES src/helper/SettingsHelper.h
    SOURCES src/helper/SettingsHelper.cpp
    SOURCES src/component/CircularReveal.cpp src/component/CircularReveal.h src/component/FileWatcher.cpp src/component/FileWatcher.h
    QML_FILES component/CodeExpander.qml
    QML_FILES viewmodel/SettingsViewModel.qml viewmodel/TextBoxViewModel.qml
    SOURCES src/singleton.h src/stdafx.h
    RESOURCES vcpkg.json
    SOURCES src/encryption/RSA.h src/encryption/RSA.cpp
    SOURCES src/tcpclient.h src/tcpclient.cpp
    SOURCES src/json.hpp
    QML_FILES window/LoginWindow.qml
    SOURCES src/encryption/caes.h src/encryption/caes.cpp
    SOURCES src/UserManager.h src/UserManager.cpp
    SOURCES src/encryption/zbase64.h src/encryption/zbase64.cpp
    SOURCES src/encryption/cipher.h src/encryption/cipher.cpp
    RESOURCES res/image/avatar_default.png
    QML_FILES global/MainGlobal.qml
    RESOURCES res/svg/avatar_1.svg res/svg/avatar_10.svg res/svg/avatar_11.svg res/svg/avatar_12.svg res/svg/avatar_2.svg res/svg/avatar_3.svg res/svg/avatar_4.svg res/svg/avatar_5.svg res/svg/avatar_6.svg res/svg/avatar_7.svg res/svg/avatar_8.svg res/svg/avatar_9.svg res/svg/home.svg res/svg/home_dark.svg
    SOURCES src/component/GuidGenerator.h src/component/GuidGenerator.cpp
    SOURCES src/protocol/Packet.hpp
    SOURCES src/model/baselistmodel.h
    SOURCES src/model/usermodel.h src/model/usermodel.cpp
    SOURCES src/model/sessionmodel.h src/model/sessionmodel.cpp
    SOURCES src/model/sessionlistmodel.h src/model/sessionlistmodel.cpp
    SOURCES src/manager/immanager.h src/manager/immanager.cpp
    SOURCES src/message.h src/message.cpp
    SOURCES src/session.h src/session.cpp
    SOURCES src/provider/userprovider.h src/provider/userprovider.cpp
    SOURCES src/component/textareadocument.h src/component/textareadocument.cpp
    SOURCES src/protocol/LoginRequest.h
    SOURCES src/protocol/LoginResponse.h
    SOURCES src/model/messagemodel.h src/model/messagemodel.cpp
    SOURCES src/model/messagelistmodel.h src/model/messagelistmodel.cpp
)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
set_target_properties(appcohub-client PROPERTIES
#    MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appcohub-client
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

target_link_libraries(appcohub-client
    PRIVATE Qt6::Quick
    fluentuiplugin
)
include_directories(
    googletest/googletest
    googletest/googletest/include)

add_subdirectory(googletest)

include(GNUInstallDirs)
install(TARGETS appcohub-client
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

add_subdirectory(FluentUI)

target_link_libraries(${PROJECT_NAME}
    PRIVATE OpenSSL::SSL OpenSSL::Crypto
)
